package cn.tedu.eg1.controller;

import cn.tedu.eg1.pojo.dto.BmiDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class BmiController {
    @GetMapping("/bmi")
    @ResponseBody
    public String bmi(BmiDto bmiDto) {
        float h = bmiDto.getHight();
        float w = bmiDto.getWeight();
        float bmi = w / (h*h);
        System.out.println(bmi);

        String i = null;

        if (bmi < 18.5) {
            i = "偏瘦";
        }else if (bmi >= 18.5 && bmi <= 24) {
            i = "正常";
        }else if (bmi >= 24 && bmi <= 27) {
            i = "微胖";
        }else if (bmi >= 27) {
            i = "该减肥了";
        }

        return i;

    }

    @GetMapping("/bmi/{hight}/{weight}")
    @ResponseBody
    public String updateBmi(@PathVariable Float hight, @PathVariable Float weight) {
        float h = hight;
        float w = weight;
        float bmi = w / (h*h);
        System.out.println(bmi);

        String i = null;

        if (bmi < 18.5) {
            i = "偏瘦";
        }else if (bmi >= 18.5 && bmi <= 24) {
            i = "正常";
        }else if (bmi >= 24 && bmi <= 27) {
            i = "微胖";
        }else if (bmi >= 27) {
            i = "该减肥了";
        }

        return i;
    }
}
